package com.ls.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ls.entity.SysPermission;
import com.ls.mapper.SysPermissionMapper;
import com.ls.service.ISysPermissionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 权限表 服务实现类
 * </p>
 *
 * @author TangQuanBin
 * @since 2019-09-13
 */
@Service
public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysPermission> implements ISysPermissionService {

    private static final Logger LOGGER = LoggerFactory.getLogger(SysPermissionServiceImpl.class);

    @Autowired
    private SysPermissionMapper sysPermissionMapper;

    @Override
    public List<SysPermission> loadAllPermissions() {
        return sysPermissionMapper.getAllPermissions();
    }

    @Override
    public List<SysPermission> findPermissionsByRoleId(Long roleId) {
        try{
            return sysPermissionMapper.findPermissionsByRoleId(roleId);
        }catch (Exception e){
            LOGGER.error("根据用户角色查询拥有权限时异常:{}" , e);
            return null;
        }
    }
}
